package com.eschool.beans.datamodels;

import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

import com.eschool.model.Student;

public class StudentDataModel extends ListDataModel<Student> implements SelectableDataModel<Student>, Serializable {  

    public StudentDataModel() {
    }

    public StudentDataModel(List<Student> data) {
        super(data);
    }
    
    @Override
    public Student getRowData(String rowKey) {
        List<Student> students = (List<Student>) getWrappedData();
        
		for (Student student : students) {
            if(Integer.toString(student.getStudentId()).equals(rowKey))
                return student;
        }
        
        return null;
    }

    @Override
    public Object getRowKey(Student student) {
        return student.getStudentId();
    }
}